package com.example.studentmanager.service.impl;

import com.example.studentmanager.service.RedisService;
import com.example.studentmanager.utils.BaseDao;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisMonitor;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class RedisServiceImpl extends BaseDao implements RedisService {


    /**
     * 获取Redis实例
     * @return
     */
    @Override
    public Jedis getJedis() {
        return super.getJedis();
    }

    public void addRedis(){
        Jedis jedis=getJedis();
        jedis.set("123","liudehua");
        System.out.println(jedis.get("123"));
        jedis.lpush("site-list", "Runoob");
        jedis.lpush("site-list", "Google");
        jedis.lpush("site-list", "Taobao");
        // 获取存储的数据并输出
        List<String> list = jedis.lrange("site-list", 0 ,2);
        Set<String> stringSet=jedis.keys("site-list");
        Iterator<String> iterator=stringSet.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }



    }


    /**
     * 关闭redis连接
     * @param jedis
     */
    @Override
    public void closeRedisConnect(Jedis jedis) {
        jedis.close();
    }





}
